//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef __PEERMALIZIOSI_CLOUD_H_
#define __PEERMALIZIOSI_CLOUD_H_

#include <omnetpp.h>
#include "BitTorrentMsg_m.h"
#include "InternalMsg_m.h"

namespace peermaliziosi {


class Cloud : public cSimpleModule
{
private:
    /*
     * Segnali per le statistiche
     */
    simsignal_t totMsgOnFlySignal;
    simsignal_t totByteOnFlySignal;
    simsignal_t totRequestSignal;
    simsignal_t totPieceSignal;
    simsignal_t totCancelSignal;

    /**
     * Coda dei messaggi di BitTorrent in uscita
     * Inserimento in coda, estrazione in testa
     */
    std::list<BitTorrentMsg*> *outgoing; // vettore di liste
    ExtractOutgoingMsg **outgoingMsg; // vettore di puntatri a msg
    int numPeers;
    std::string& outgoingStr(int queueIndex);
    void pushOutgoingMsg(BitTorrentMsg *msg);
    void popOutgoingMsgAndSend(int queueIndex);
protected:
    virtual void initialize();
    virtual void finish();
    virtual void handleMessage(cMessage *msg);
public:
    Cloud();
    virtual ~Cloud();
};

} //namespace

#endif
